<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
   <title>FishVideo信息管理平台</title>
   <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  <style>
	.table th{
		text-align:center;
	}
	.table td{
		text-align:center;
	}
	#left{
		width:20%;
		float:left;
	}
	#content{
		width:80%;
		margin-left:20%;
	}
	#info{
		font-size:20px;
	}
	#add{
		float:right;
	}
	 #pageButton{
			width:80%;
			margin-left:10%;
	   }
	   #leftbutton{
			width:50%;
			
	   }
	   #rightbutton{
			width:50%;
			margin-left:50%;
			
	   }
  </style>
</head>
<body>
	<?php require_once("control_daohang.php")?>
	<div class="container" id=left>
		<?php require_once("menu.html"); ?>
	</div>
	<div id="content">
		<div id="add"><a href="#" data-toggle="modal"  data-target="#register">添加视频&nbsp&nbsp&nbsp</a></div>
		<table class="table">
		<tr><th>序号</th><th>视频名称</th><th>分类</th><th>缩略图</th><th>剧情介绍</th><th>影片宣传介绍</th><th>上传日期</th><th>点击次数</th><th>下载次数</th><th>视频地址</th><th>上传人</th><th>操作</th></tr>
			<?php
				require_once("../utils/upload.php");
				require_once("../utils/db.php");
				$conn=connect();
				$realpath="../video/upload/";
			?>
			<?php			
			if(isset($_POST['addVideo'])){//上传视频
				$pic=GetPic("pic","../video/upload/",0);//缩略图地址
				$address=GetPic("address","../video/upload/",1);//视频名称
				
				$sql="insert into fishvideo_video values(null,'{$_POST['videoname']}','{$_POST['tid']}'
				,'{$pic}','{$_POST['intro']}','{$_POST['lintro']}',NOW(),'{$_SESSION['adminid']}',0,0,'{$address}')";
				
				//echo $sql;
				if(!mysql_query($sql)){
					echo "<script>alert('上传失败！');</script>";
				}
			}
			if(isset($_GET['id'])){//删除
				$sql="delete from fishvideo_video where yjl_vid='{$_GET['id']}';";
				//echo $sql;
				if(!mysql_query($sql,$conn)){
					echo "<script>alert('删除失败!');</script>";
				}else{
				unlink($realpath.$_GET['path']);//物理删除
				unlink($realpath.$_GET['vpath']);//物理删除
				}
			}
			$sql="select * from fishvideo_video";
			if(isset($_POST['search'])){//查询
				$sql.=" where yjl_videoname like '%{$_POST['videoname']}%' ";
			}
			//echo $sql;
			$result=mysql_query($sql,$conn);
			$sumnumber=mysql_num_rows($result);
			//echo $sql;
			//分页
			if(!isset($_GET['page'])){//如果没有
					$page=0;
				}else{
					$page=$_GET['page'];
				}
				$perpage=10;//每页10个
				$pagenumberq=$page*10;
				$sql.=" limit {$pagenumberq},{$perpage}";
				//echo $sql;
				$ym=($pagenumberq+$perpage);
				if($ym>($sumnumber)) $ym=($sumnumber);
			$result=mysql_query($sql,$conn);
			$ct=0;
			$arr=array("yjl_videoname","yjl_tid","yjl_pic","yjl_intro","yjl_lintro","yjl_uploaddate",
			"yjl_clicktimes","yjl_downtimes","yjl_address","yjl_uploadadmin");
			for($cc=($pagenumberq+1);$cc<=$ym;$cc++){
				echo "<tr><td>{$cc}</td>";
				$row=mysql_fetch_array($result);
				
					for($i=0;$i<count($arr);$i++){
						
						$ans=$row[$arr[$i]];
						if(1==$i){
							$sql="select yjl_typename from fishvideo_videotype where yjl_tid='{$row[$arr[$i]]}'";
							$ans=mysql_query($sql);
							$ans=mysql_fetch_array($ans);
							$ans=$ans[0];
						}else if(9==$i){
							$sql="select yjl_adminname from fishvideo_admins where yjl_adminid='{$row[$arr[$i]]}'";
							//echo $sql;
							$ans=mysql_query($sql);
							$ans=mysql_fetch_array($ans);
							$ans=$ans[0];
						}else if(2==$i){//图片	
							$path=$ans;
							echo "<td><img src='{$realpath}{$path}' width='60px' height='60px'></td>";
							//echo $path;
							continue;
						}else if(8==$i){//视频地址
							echo "<td><a href='{$realpath}{$ans}'>点击播放</a></td>";
							continue;
						}
						echo "<td>{$ans}</td>";
				}
				echo "<td><a href='doUpdateVideo.php?id={$row['yjl_vid']}'>修改</a> </form> | 
				<a onclick=\"confirm('确定要删除吗')?
location.href='control_video.php?id={$row['yjl_vid']}&path={$path}&vpath={$row[$arr[8]]}':''\" href=\"javascript:;\">删除</a></td>";
				
			}
			mysql_close($conn);
			?>
<tr>
<!--分页 -->
	  <div id="dispage">
		<span>
		 <?php
			if($sumnumber%$perpage==0)
			$sumpage=(int)($sumnumber/$perpage);
			else $sumpage=(int)(($sumnumber/$perpage)+1);
				$now =$page+1;
		    echo "共有{$sumnumber}条数据，当前第({$now}/{$sumpage})页";
		?>
		</span>
		<span>
		<?php
		echo "<a href='control_video.php?page=0'>首页</a> ";
		if($page!=0){
		$now = $page-1;
		echo "<a href='control_video.php?page={$now}'>上一页</a> ";
		}
		if($page!=($sumpage-1)){
			$now = $page+1;
		echo "<a href='control_video.php?page={$now}'>下一页</a> ";
		}
		$now=$sumpage-1;
		echo "<a href='control_video.php?page={$now}'>尾页</a>";
		?>
		</span>
	</div>		
	</tr>
		</table>
	</div>
	
	<!-- 模态框（Modal）（注册） -->
<div class="modal fade" id="register" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
	   <div class="modal-dialog">
		  <div class="modal-content">
			 <div class="modal-header">
				<button type="button" class="close" 
				   data-dismiss="modal" aria-hidden="true">
					  &times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
				   请填写影片信息
				</h4>
			 </div>
			 <!--上传主体 -->
			 <div class="modal-body">
		<form method="POST" action="control_video.php" enctype="multipart/form-data">
			<table class="table">
				<tr><th>影片名称</th><td><input type="text" class="form-control" required="required" name="videoname"></td></tr>
				<tr><th>影片类型</th>
				<td><select class="form-control" required="required" name="tid">
					<?php						
							require_once("../utils/upload.php");
							require_once("../utils/db.php");
							$conn=connect();						
							$sql="select * from fishvideo_videotype";
							$result = mysql_query($sql);
							while($row = mysql_fetch_array($result)){//得到每一列的结果
							echo "<option value='{$row['yjl_tid']}'>{$row['yjl_typename']}</option>";
						}
						mysql_close($conn);
					?>
				</select></td>
				<tr><th>缩略图</th><td><input type="file" class="form-control" name="pic"></td></tr>
				<tr><th>影片介绍</th><td><textarea name="intro" class="form-control" rows="3" cols="20"
				placeholder="剧情介绍。。。。。"></textarea></td></tr>
				<tr><th>影片宣传介绍</th><td><input type="text" name="lintro" class="form-control" rows="3" cols="20"
				placeholder="简短引言，宣传语。。。。。"></td></tr>
				<tr><th>上传影片</th><td><input type="file" class="form-control" name="address"></td></tr>
			</table>		
			<div id="pageButton">
				<span id="leftbutton">
				<button type="button" class="btn btn-default" 
					   data-dismiss="modal">关闭
					</button>
				</span>
				<span id="rightbutton">
					<button type="submit" name="addVideo" class="btn btn-primary">
					   上传
					</button>
				</span>
			</div>
		 </form>
		</div>
	</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</body>
</html>